<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset id="searchFieldset_currentTable" class="table-search-fieldset layui-hide">
            <legend>{:lang("common.condition_search")}</legend>
            <form class="layui-form layui-form-pane form-search">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("common.start_month")}</label>
                    <div class="layui-input-inline">
                        <input name="coll_collect_month_ge" class="layui-input cssMonth"
                               placeholder="{:lang('common.choose')}{:lang('common.start_month')}"
                               value="{$param.coll_collect_month_ge|default=''}">
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("common.end_month")}</label>
                    <div class="layui-input-inline">
                        <input name="coll_collect_month_le" class="layui-input cssMonth"
                               placeholder="{:lang('common.choose')}{:lang('common.end_month')}"
                               value="{$param.coll_collect_month_le|default=''}">
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("custom.name")}</label>
                    <div class="layui-input-inline">
                        <select name="coll_custom_id_eq" lay-search>
                            <option value="">{:lang("common.choose")}{:lang("custom.name")}</option>
                            {foreach :getMyCustomList() as $val}
                            <option value="{$val.id}">{$val.number}{$val.name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>

                {if !auth('roleAccounting')}
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("accounting.name")}</label>
                    <div class="layui-input-inline">
                        <select name="coll_accounting_id_eq" lay-search>
                            <option value="">{:lang("common.choose")}{:lang("accounting.name")}</option>
                            {foreach :getAccountingList() as $val}
                            <option value="{$val.id}">{$val.name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                {/if}

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("collect.serve_type")}</label>
                    <div class="layui-input-inline">
                        <select name="coll_serve_type_eq" data-select-type="serve_type_list"
                                data-select-default="{:lang('common.choose')}"
                                default-value="{$param.coll_serve_type_eq|default=''}">
                        </select>
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("collect.invoice_status")}</label>
                    <div class="layui-input-inline">
                        <select name="coll_invoice_status_eq" data-select-type="collect_invoice_status_list"
                                data-select-default="{:lang('common.choose')}"
                                default-value="{$param.coll_invoice_status_eq|default=''}">
                        </select>
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("collect.status")}</label>
                    <div class="layui-input-inline">
                        <select name="coll_status_eq" data-select-type="collect_status_list"
                                data-select-default="{:lang('common.choose')}"
                                default-value="{$param.coll_status_eq|default=''}">
                        </select>
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("collect.collect_date_start")}</label>
                    <div class="layui-input-inline">
                        <input name="coll_collect_date_ge" class="layui-input cssDate"
                               placeholder="{:lang('common.choose')}{:lang('collect.collect_date_start')}"
                               value="{$param.coll_collect_date_ge|default=''}">
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("collect.collect_date_end")}</label>
                    <div class="layui-input-inline">
                        <input name="coll_collect_date_le" class="layui-input cssDate"
                               placeholder="{:lang('common.choose')}{:lang('collect.collect_date_end')}"
                               value="{$param.coll_collect_date_le|default=''}">
                    </div>
                </div>

                <div class="layui-form-item layui-inline" style="margin-left:50px">
                    <button type="submit" class="layui-btn layui-btn-normal" data-type="tableSearch"
                            lay-submit lay-filter="search_currentTable">{:lang("common.btn_search")}
                    </button>
                </div>
            </form>
        </fieldset>

        <table id="currentTable"
               data-auth-add="{:auth(request()->controller().'/add')}"
               data-auth-edit="{:auth(request()->controller().'/edit')}"
               data-auth-delete="{:auth(request()->controller().'/delete')}"
               data-auth-print="{:auth(request()->controller().'/print')}"
               data-auth-export="{:auth(request()->controller().'/export')}">
        </table>
    </div>
</div>
<script>
    layui.use(['myApp'], function () {
        var myCommon = layui.myCommon;
        window.editCollect = function (id) {
            popupWindow('{:lang("collect.see_title")}', 'tally.collect/edit?id=' + id, function () {
                myCommon.api.refreshTable();
            }, 800);
        }

        var columns = [
            {type: "checkbox"}
            , {field: 'id', width: 60, title: '{:lang("common.id")}', sort: true}
            , {field: '_month', width: 70, title: '{:lang("common.month")}', sort: true}
            , {field: 'number', width: 105, title: '{:lang("custom.number")}', sort: true}
            , {field: 'custom_name', minWidth: 120, title: '{:lang("custom.name")}', sort: true}
            , {field: 'accounting_name', width: 105, title: '{:lang("accounting.name")}', sort: true}
            , {
                field: 'invoice_type', width: 90, title: '{:lang("collect.invoice_type")}', sort: true,
                templet: myCommon.table.type, typeList: 'invoice_type_list'
            }
            , {
                field: 'serve_type', width: 90, title: '{:lang("collect.serve_type")}', sort: true,
                templet: myCommon.table.type, typeList: 'serve_type_list'
            }
            , {field: 'article', minWidth: 100, title: '{:lang("collect.article")}'}
            , {
                field: 'money', width: 80, title: '{:lang("collect.money")}'
                , templet: myCommon.table.fn, fn: function (value, data) {
                    return '<a onclick="return editCollect(' + myCommon.value(data, 'id') + ')">' + value + '</a>';
                }
            }
            , {field: 'remark', minWidth: 100, title: '{:lang("collect.remark")}'}
            , {
                field: 'invoice_status', width: 60, title: '{:lang("collect.invoice_status")}', sort: true,
                templet: myCommon.table.type, typeList: 'collect_invoice_status_list'
            }
            , {field: 'invoice_date', width: 90, title: '{:lang("collect.invoice_date")}'}
            , {
                field: 'status', width: 60, title: '{:lang("collect.status")}', sort: true,
                templet: myCommon.table.type, typeList: 'collect_status_list'
            }
            , {field: 'collect_date', width: 90, title: '{:lang("collect.collect_date")}'}
            , {field: 'first_date', width: 90, title: '{:lang("collect.first_date")}'}
            , {field: 'second_date', width: 90, title: '{:lang("collect.second_date")}'}
        ];
        if (myCommon.checkAuth('delete', '#currentTable')) {
            columns.push({
                width: 50, title: '{:lang("common.operate")}', templet: myCommon.table.tool, operat: ['delete']
            });
        }
        myCommon.table.render({
            where: myCommon.generateCondition()
            , totalRow: true
            , limit: "{$param.limit|default='15'}"
            , cols: [columns]
            , done: function (res) {
                myCommon.tableTotal(this, res.data, ['money']);
            }
        });
        myCommon.listen();
    });
</script>
